package com.memorypalace.action;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.memorypalace.deck.biz.NoteBiz;
import com.memorypalace.deck.biz.NoteTypeBiz;
import com.memorypalace.pojo.Note;
import com.memorypalace.pojo.NoteType;
import com.memorypalace.util.AJaxUtil;

@Controller
@RequestMapping("/note")
public class NoteAction {

	@Autowired
	private NoteBiz noteBiz;
	@Autowired
	private NoteTypeBiz noteTypeBiz;
	
	@RequestMapping("/getnotebynoteid")
	@ResponseBody
	public void getNoteByNoteId(String noteId,HttpServletRequest request,HttpServletResponse response){
		Note note = noteBiz.getNoteByNoteId(noteId);
		String noteTypeId = note.getNoteType().getNoteTypeId();
		NoteType noteType = noteTypeBiz.getNoteTypeByNoteTypeId(noteTypeId);
		note.setNoteType(noteType);
		AJaxUtil.sendJsonByObj(note, response);
	}
	
	
	
	@RequestMapping("/editnote")
	@ResponseBody
	public void editNoteType(Note note,HttpServletResponse response){
		note.setNoteEditTime(new Date());
		Integer result = noteBiz.updateNote(note);
		AJaxUtil.sendJsonByObj(result, response);
	}
	
	
	@RequestMapping("/addnote")
	@ResponseBody
	public void addNote(Note note,HttpServletResponse response){
		
		Boolean addFlag=noteBiz.addNote(note);
		AJaxUtil.sendJsonByObj(addFlag, response);
		
	}
	@RequestMapping("/deletenote")
	@ResponseBody
	public void deleteNote(String noteId,HttpServletResponse response){
		
		Boolean deleteFlag=noteBiz.deleteNote(noteId);
		System.out.println("deleteNote noteId:"+noteId);
		AJaxUtil.sendJsonByObj(deleteFlag, response);
		
	}
	
	
	
}
